<?php
declare (strict_types=1);

namespace app\api\controller;

use app\common\model\Assets;
use app\common\model\Account as AccountModel;
use app\common\tool\Result;
use think\facade\View;
use think\response\Json;

class Account extends Base
{

    public function index()
    {

        $list = Assets::getFields(3);
        $result = [];
        foreach ($list as $key => $v) {
            $result[] = [
                'title' => $v,
                'account' => $key,
                'balance' => $this->user->assets->$key
            ];
        }
        return Result::success('获取成功',$result);
    }


    /**
     * get: 流水
     * path: getList
     * method: getList
     * param: page - {string} 页数
     * param: type - {string} 账户
     */
    public function getList()
    {
        $param = $this->request->get();
        $map = ['type' => $param['type'], 'uid' => $this->user->id];
        $List = AccountModel::getPageList($map, 'intro,type,amount,fx,create_time', $param['page'], 20, false, ['take']);
//        $List['data']['balance'] = $this->user->assets->balance;
        if($List['code']>0)
        {
            return Result::success('获取成功',$List['data']);
        }else{
            return Result::fail('获取失败');
        }
    }
}

